home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Software Contest 3
/
FM Towns Software Contest 3.iso
/
exp
/
astral
/
a1
/
game
/
source
/
afmain.c
next >
Wrap
C/C++ Source or Header
|
1994-01-07
|
12KB
|
564 lines
// "afmain.c"
// ASTRAL FORCE メインルーチン
#define MAIN
#include <stdlib.h>
#include <stdio.h>
#include <egb.h>
#include <spr.h>
#include <snd.h>
#include <mos.h>
#include <time.h>
#include "wire3d.h"
#include "sin8.c"
#include "scmds.h"
// マクロ設定
#define LENGTH 1000
#define JOY_UP(A) if((A&0x01)==0)
#define JOY_DOWN(A) if((A&0x02)==0)
#define JOY_LEFT(A) if((A&0x04)==0)
#define JOY_RIGHT(A) if((A&0x08)==0)
#define JOY_TRIG_A(A) if((A&0x10)==0)
#define JOY_TRIG_B(A) if((A&0x20)==0)
#define JOY_SELECT(A) if((A&0x03)==0)
#define JOY_RUN(A) if((A&0x0c)==0)
// グローバル変数設定
static char Mwork[4096],Gwork[1536],Swork[16384];
extern WIRE_OBJECT Object[];
extern int End_code;
extern int Count;
int Screen_mode=0;
int Sight_x,Sight_y;
int Score=0;
int High_score=0;
int Shield;
int Laser=0;
int Crush_time=0;
int Start_time;
int Laser_color=0;
char SE_crush[16000],SE_hit[1600],SE_dammage[6000];
int movdata[4096],demomov[4096];
extern int N_page,W_page;
extern WIRE_SPACE Space[32];
extern SCREEN_LOCATE Screen[32];
extern int Hit_point[32];
extern int Hit_size[32];
extern int Hit_score[32];
extern int Hit_my_fighter[32];
extern int Offset[3];
extern ANGLE Angle[3];
void screen_init(int mode)
// mode...0:High.Normal
// 1:High.Wide
// 2:Low .Normal
// 3:Low .Wide
{
int i;
if(mode<0 || mode>3)
mode=0;
switch(mode){
case 0:
case 1:
EGB_resolution(Gwork,0,5);
EGB_resolution(Gwork,1,5);
break;
case 2:
case 3:
EGB_resolution(Gwork,0,8);
EGB_resolution(Gwork,1,8);
break;
}
for(i=0;i<2;i++){
EGB_writePage(Gwork,i);
EGB_clearScreen(Gwork);
EGB_displayStart(Gwork,1,0,0);
switch(mode){
case 0:
case 1:
EGB_displayStart(Gwork,0,64,0);
EGB_displayStart(Gwork,2,2,2);
break;
case 2:
EGB_displayStart(Gwork,0,32,0);
EGB_displayStart(Gwork,2,4,1);
break;
case 3:
EGB_displayStart(Gwork,0,0,0);
EGB_displayStart(Gwork,2,5,1);
break;
}
EGB_displayStart(Gwork,3,256,240);
}
if(mode==1){
CRTC_out(0,80);
CRTC_out(1,590);
CRTC_out(4,669);
CRTC_out(29,3);
CRTC_out(9,130);
CRTC_out(18,130);
CRTC_out(10,642);
CRTC_out(11,130);
CRTC_out(22,130);
CRTC_out(12,642);
}
line(0,0,255,0,0x8000,2);
line(0,1,255,1,0x8000,2);
line(0,0,255,0,0x8000,3);
line(0,1,255,1,0x8000,3);
EGB_displayPage(Gwork,1,3);
}
void movedata_anarize(char *source,int *movdata)
{
int i,j=0,k=0,sgn=1;
for(i=0;i<32768;i++){
switch(source[i]){
case '#':
while(source[++i]!='\n');
continue;
case ' ' :
case '\n':
case '\t':
continue;
case ',':
movdata[j++]=k*sgn;
k=0;
sgn=1;
continue;
case '-':
sgn=-1;
continue;
case '$':
return;
default:
if(source[i]>='0' && source[i]<='9'){
k*=10;
k+=source[i]-'0';
}
else{
goto ERROR;
}
continue;
}
}
return;
ERROR:
printf("movファイルの書式に誤りがあります");
return;
}
void title_demo_option(void){
int i,j,k;
switch(Laser_color){
case 0:
Object[3].color=COLOR(16,31,0);
Object[2].color=COLOR(12,0,31);
Laser_color=1;
break;
case 1:
Object[2].color=COLOR(31,12,31);
Object[3].color=COLOR(31,31,16);
Laser_color=0;
break;
}
MOS_rdpos(&i,&j,&k);
switch(i){
case 1:
End_code=1;
break;
case 2:
if((++Screen_mode)==4)Screen_mode=0;
screen_init(Screen_mode);
break;
}
if((pad_in()|0xc0)!=0xff){
End_code=2;
}
}
void title_demo(void)
{
int i,j,k;
for(i=0;i<128;i++){
SPR_set_att(1023-i,1,1,0,0x2000);
}
SPR_set_att_pos(896+20,13,1,(128+147),0x8100,24,64);
// putstrg(80,64,896+20,"ASTRAL FORCE",12);
putstrg(56,168,896+34,"LEFT BUTTON",12);
putstrg(56,180,896+46,"> GAME START ",20);
putstrg(56,200,896+66,"RIGHT BUTTON",12);
putstrg(56,212,896+78,"> CHANGE SCREEN MODE",20);
for(i=0;i<8;i++){ // スコア表示
SPR_set_att_pos(896+112+i,1,1,(128+2),0x8100,128+i*8,4);
}
SPR_set_att_pos(896+120,4,1,(128+143),0x8100,64,8);
put_score(High_score);
do{
MOS_rdpos(&i,&j,&k);
}while(i!=0);
do{
Count=0;
pilot(demomov,title_demo_option);
}while(End_code==0);
return;
}
int game_over(void)
{
int i,j,k;
switch(End_code){
case 0:
putstrg(92,64,896+20,"TIME OVER",9);
break;
case 1:
putstrg(60,64,896+20,"YOU ARE DESTROYED.",18);
clear_screen(W_page,COLOR(4,8,0));
star(Angle,W_page);
wirespace(Angle,Offset,32,W_page);
wait_VSYNC();
chgpage(W_page);
break;
}
if(Score>High_score){
High_score=Score;
}
do{
MOS_rdpos(&i,&j,&k);
}while(i!=0);
for(;;){
MOS_rdpos(&i,&j,&k);
if(i!=0){
Score=0;
End_code=0;
return 0;
}
if((pad_in()|0xc0)!=0xff){
return 1;
}
}
}
void game_sub(void)
{
int button,i;
put_count(LENGTH-Count);
MOS_rdpos(&button,&Sight_x,&Sight_y);
SPR_set_pos(896+16,2,1,Sight_x,Sight_y);
Crush_time--;
SPR_set_att(896+0,4,4,128+46+Crush_time*16,0x8100);
if(Crush_time==0){
SPR_set_pos(896+0,4,4,256,256);
}
switch(Laser_color){
case 0:
Object[2].color=COLOR(12,0,31);
Object[3].color=COLOR(16,31,0);
Laser_color=1;
break;
case 1:
Object[2].color=COLOR(31,12,31);
Object[3].color=COLOR(31,31,16);
Laser_color=0;
break;
}
if(Start_time!=0){
switch((Start_time>>2)%2){
case 0:
putstrg(108,80,896+20," ",5);
break;
case 1:
putstrg(108,80,896+20,"START",5);
break;
}
Start_time--;
return;
}
switch(button){
case 1:
if(Laser==0){
line(0,255,Sight_x,Sight_y,COLOR(16,0,31),W_page);
line(4,255,Sight_x,Sight_y,COLOR(16,0,31),W_page);
line(2,255,Sight_x,Sight_y,COLOR(31,0,31),W_page);
line(251,255,Sight_x,Sight_y,COLOR(16,0,31),W_page);
line(255,255,Sight_x,Sight_y,COLOR(16,0,31),W_page);
line(253,255,Sight_x,Sight_y,COLOR(31,0,31),W_page);
Laser=1;
}
else{
Laser=0;
}
for(i=0;i<32;i++){
if(Hit_point[i]!=0 && Space[i].obj_no!=-1 && \
Sight_x>=Screen[i].locate[0]-Hit_size[i] && \
Sight_x<=Screen[i].locate[0]+Hit_size[i] && \
Sight_y>=Screen[i].locate[1]-Hit_size[i] && \
Sight_y<=Screen[i].locate[1]+Hit_size[i] && \
Screen[i].locate[2]>-(Object[Space[i].obj_no].size)){
SND_pan_set(70,Screen[i].locate[0]>>1);
SND_pcm_play_stop(70);
SND_pcm_play(70,70,127,SE_hit);
if((--Hit_point[i])==0){
SND_pan_set(71,Screen[i].locate[0]>>1);
SND_pcm_play_stop(71);
SND_pcm_play(71,60,127,SE_crush);
Crush_time=2;
if(Screen[i].locate[2]>3000){
SPR_set_att_pos(896+0,4,4,128+46+Crush_time*16-32 , \
0x8100,Screen[i].locate[0]-32,Screen[i].locate[1]-32);
}
else{
SPR_set_att_pos(896+0,4,4,128+46+Crush_time*16, \
0x8100,Screen[i].locate[0]-32,Screen[i].locate[1]-32);
}
Score+=Hit_score[i];
if(Score<0){
Score=0;
}
put_score(Score);
Space[i].obj_no=-1;
break;
}
}
}
break;
}
for(i=0;i<32;i++){
if(Hit_my_fighter[i]!= 0 && Space[i].obj_no!=-1 && \
Screen[i].locate[0]>=-150 && \
Screen[i].locate[0]<= 405 && \
Screen[i].locate[1]>=-150 && \
Screen[i].locate[1]<= 405 && \
Screen[i].locate[2]>=-500 && \
Screen[i].locate[2]<= 200 ){
SND_pan_set(70,64);
SND_pcm_play_stop(70);
SND_pcm_play(70,60,127,SE_dammage);
if((--Shield)==0){
End_code=1;
}
put_shield(Shield);
Space[i].obj_no=-1;
clear_screen(N_page,COLOR(31,31,31));
break;
}
}
if((pad_in()|0xc0)!=0xff){
End_code=2;
}
}
void main(void)
{
int i;
FILE *str1;
clock_t start_clock;
char filebuf[32768];
for(i=0;i<4096;i++){
Mwork[i]=0;
}
printf("ASTRAL FORCE 30秒バージョン\n");
printf("Program : Version 0.11\n");
printf("Data : Version 0.02\n");
EGB_init(Gwork,1536);
SND_init(Swork);
MOS_start(Mwork,4096);
screen_init(Screen_mode);
SPR_init();
SND_pcm_mode_set(2);
SND_elevol_mute(0x3f);
str1=fopen("game.mov","r");
fread((void *)(filebuf),32768,1,str1);
fclose(str1);
movedata_anarize(filebuf,movdata);
str1=fopen("demo.mov","r");
fread((void *)(filebuf),32768,1,str1);
fclose(str1);
movedata_anarize(filebuf,demomov);
str1=fopen("crush.snd","rb");
fread((void *)(SE_crush),32768,1,str1);
fclose(str1);
str1=fopen("hit.snd","rb");
fread((void *)(SE_hit),1600,1,str1);
fclose(str1);
str1=fopen("dammage.snd","rb");
fread((void *)(SE_dammage),6000,1,str1);
fclose(str1);
str1=fopen("sprdata.azc","rb");
if(str1==NULL){
printf("パレット設定ファイルの読出に失敗しました\n");
goto EXIT_main;
}
fread((void *)(filebuf),8192,1,str1);
fclose(str1);
SPR_setPaletteBlock(256,256,filebuf);
str1=fopen("sprdata.azg","rb");
if(str1==NULL){
printf("パターン定義ファイルの読出に失敗しました\n");
goto EXIT_main;
}
fread((void *)(filebuf),32768,1,str1);
fclose(str1);
MOS_pulse(8,8);
MOS_disp(0);
MOS_horizon(0,255);
MOS_vertical(0,239);
// 照準 0-1
SPR_define(0,128+0,2,1,filebuf+128*(16*0+0));
// 数字 2-11
for(i=0;i<10;i++){
SPR_define(0,128+2+i,1,1,filebuf+128*(16*1+i));
}
// COUNT 12-13
SPR_define(0,128+12,2,1,filebuf+128*(16*4+2));
// 文字 14-45
for(i=0;i<32;i++){
SPR_define(0,128+14+i,1,1,filebuf+128*(16*2+i));
}
// 爆発 46-110
for(i=0;i<4;i++){
SPR_define(0,128+46+i*16,4,1,filebuf+128*(16*6+i*4));
SPR_define(0,128+50+i*16,4,1,filebuf+128*(16*7+i*4));
SPR_define(0,128+54+i*16,4,1,filebuf+128*(16*8+i*4));
SPR_define(0,128+58+i*16,4,1,filebuf+128*(16*9+i*4));
}
// SCORE 122-123
SPR_define(0,128+122,2,1,filebuf+128*(16*4+0));
// シールド表示の枠 124-132
SPR_define(0,128+124,4,1,filebuf+128*(16*4+4));
SPR_define(0,128+128,4,1,filebuf+128*(16*5+4));
// シールド 132-133
SPR_define(0,128+132,1,1,filebuf+128*(16*4+8));
SPR_define(0,128+133,1,1,filebuf+128*(16*4+9));
// カウント表示の枠 134-142
SPR_define(0,128+134,4,1,filebuf+128*(16*4+10));
SPR_define(0,128+138,4,1,filebuf+128*(16*5+10));
// HIGH-SCORE 143-146
SPR_define(0,128+143,4,1,filebuf+128*(16*5+0));
// タイトル文字 147-159
SPR_define(0,128+147,13,1,filebuf+128*(16*10+0));
SPR_setOffset(-15,-7);
SPR_display(1,128);
for(;;){
title_demo();
if(End_code==2){
break;
}
End_code=0;
Count=0;
Shield=4;
for(i=0;i<128;i++){
SPR_set_att(1023-i,1,1,0,0x2000);
}
SPR_set_att_pos(896+16,2,1,(128+0) | 0x8000,0x8100,128,128);
SPR_set_att_pos(896+90,4,2,(128+134),0x8100,192,208);
for(i=0;i<5;i++){
SPR_set_att_pos(896+123+i,1,1,(128+2),0x8100,206+i*8,218);
}
for(i=0;i<8;i++){
SPR_set_att_pos(896+112+i,1,1,(128+2),0x8100,112+i*8,4);
}
SPR_set_att_pos(896+110,2,1,(128+122),0x8100,80,8);
SPR_set_att_pos(896+0,4,4,(128+40),0x8100,256,256);
SPR_set_att_pos(896+102,4,2,(128+124),0x8100,0,208);
SPR_set_att_pos(896+98,1,1,(128+132),0x8100,8,216);
for(i=0;i<3;i++){
SPR_set_att_pos(896+99+i,1,1,(128+133),0x8100,16+i*8,216);
}
Start_time=32;
put_shield(Shield);
start_clock=clock();
pilot(movdata,game_sub);
start_clock=clock()-start_clock;
if(End_code==2){
break;
}
if(game_over()==1)break;
}
EXIT_main:
SPR_display(0,2);
MOS_end();
SND_end();
printf("End...\n");
printf("総実行時間 :%2.2f秒\n",(double)((double)start_clock/ \
(double)CLK_TCK));
printf("平均描画枚数:%2.2f枚/秒\n",(double)LENGTH / \
((double)start_clock/(double)CLK_TCK));
}